<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户管理</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Arial', sans-serif;
            background-color: #f4f7fa;
            display: flex;
            min-height: 100vh;
        }

        .sidebar {
            width: 240px;
            background-color: #34495e;
            padding: 20px;
            color: white;
            box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .sidebar h2 {
            font-size: 20px;
            margin-bottom: 20px;
            text-align: center;
        }

        .sidebar a {
            display: block;
            margin-bottom: 15px;
            text-decoration: none;
            color: white;
            padding: 12px;
            width: 100%;
            background-color: #2c3e50;
            border-radius: 5px;
            text-align: center;
            font-size: 16px;
            transition: background-color 0.3s ease;
        }

        .sidebar a:hover {
            background-color: #1abc9c;
        }

        .content {
            flex: 1;
            padding: 40px;
            background-color: #ffffff;
            border-radius: 8px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
        }

        h1 {
            font-size: 28px;
            color: #2c3e50;
            margin-bottom: 30px;
            border-bottom: 2px solid #ecf0f1;
            padding-bottom: 10px;
        }

        form {
            margin-bottom: 30px;
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
            justify-content: flex-start;
        }

        label {
            font-size: 16px;
            margin-right: 10px;
            color: #555;
            align-self: center;
        }

        input[type="text"] {
            padding: 10px;
            font-size: 14px;
            width: 250px;
            border: 1px solid #ccc;
            border-radius: 5px;
            margin-right: 10px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        }

        button[type="submit"] {
            padding: 10px 20px;
            background-color: #2ecc71;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s ease;
        }

        button[type="submit"]:hover {
            background-color: #27ae60;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 30px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
        }

        table th,
        table td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ecf0f1;
        }

        table th {
            background-color: #f4f6f9;
            color: #7f8c8d;
        }

        table td {
            background-color: #ffffff;
        }

        table tr:hover {
            background-color: #f9f9f9;
        }

        .status-pending {
            color: white;
            background-color: #e67e22;
            padding: 5px;
            border-radius: 5px;
            text-align: center;
        }

        .status-approved {
            color: white;
            background-color: #27ae60;
            padding: 5px;
            border-radius: 5px;
            text-align: center;
        }

        .status-rejected {
            color: white;
            background-color: #e74c3c;
            padding: 5px;
            border-radius: 5px;
            text-align: center;
        }

        .status-deactivated {
            color: white;
            background-color: #95a5a6;
            padding: 5px;
            border-radius: 5px;
            text-align: center;
        }

        .action-btns button {
            padding: 6px 12px;
            font-size: 14px;
            border-radius: 5px;
            cursor: pointer;
            border: none;
            transition: background-color 0.3s ease;
            margin-right: 8px;
        }

        .action-btns .approve-btn {
            background-color: #3498db;
            color: white;
        }

        .action-btns .approve-btn:hover {
            background-color: #2980b9;
        }

        .action-btns .reject-btn {
            background-color: #e74c3c;
            color: white;
        }

        .action-btns .reject-btn:hover {
            background-color: #c0392b;
        }

        .action-btns .deactivate-btn {
            background-color: #f39c12;
            color: white;
        }

        .action-btns .deactivate-btn:hover {
            background-color: #e67e22;
        }

        .action-btns .reset-btn {
            background-color: #9b59b6;
            color: white;
        }

        .action-btns .reset-btn:hover {
            background-color: #8e44ad;
        }
    </style>
</head>
<body>

<div class="sidebar">
    <h2>团队管理员功能菜单</h2>
    <a href="/admin/achievementmanagement">科研成果管理与发布</a>
    <a href="/admin/usermanagement">用户管理</a>
    <a href="/admin/articlesManagement">文章管理</a>
    <a href="/admin/FeedbacksManagement">反馈管理</a>
    <a href="/admin/teamadmin/teammanagement">团队管理</a>
    <a href="/logout">退出</a>
</div>

<div class="content">
    <h1>用户管理</h1>

    <!-- 搜索框 -->
    <form method="GET" action="/admin/usermanagement">
        <div>
            <label for="nickname">用户昵称:</label>
            <input type="text" name="nickname" id="nickname" value="${param.nickname}" placeholder="请输入用户昵称" />
            <button type="submit">搜索</button>
        </div>
    </form>

    <!-- 显示所有用户 -->
    <table>
        <thead>
        <tr>
            <th>用户昵称</th>
            <th>注册时间</th>
            <th>申请理由</th>
            <th>邮箱</th>
            <th>用户状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <!-- 遍历所有用户并显示 -->
        <c:forEach var="user" items="${users}">
            <tr>
                <td>${user.nickname}</td>
                <td>${user.registrationTime}</td>
                <td>${user.applicationReason}</td>
                <td>${user.email}</td>
                <td>
                    <c:choose>
                        <c:when test="${user.status == 0}">
                            <span class="status-pending">待审核</span>
                        </c:when>
                        <c:when test="${user.status == 1}">
                            <span class="status-approved">已通过</span>
                        </c:when>
                        <c:when test="${user.status == 2}">
                            <span class="status-rejected">不通过</span>
                        </c:when>
                        <c:when test="${user.status == 3}">
                            <span class="status-deactivated">已注销</span>
                        </c:when>
                    </c:choose>
                </td>
                <td class="action-btns">
                    <!-- 如果用户是待审核状态 (status = 0) -->
                    <c:if test="${user.status == 0}">
                        <a href="/admin/users/approve/${user.userId}">
                            <button type="button" class="approve-btn">通过</button>
                        </a>
                        <a href="/admin/users/reject/${user.userId}">
                            <button type="button" class="reject-btn">拒绝</button>
                        </a>
                    </c:if>

                    <!-- 如果用户状态是已通过 -->
                    <c:if test="${user.status == 1}">
                        <form method="POST" action="/admin/users/deactivate/${user.userId}" style="display:inline;">
                            <button type="submit" class="deactivate-btn" onclick="return confirm('确定注销此账户吗？注销后该用户将无法登录。')">注销</button>
                        </form>
                        <form method="POST" action="/admin/users/resetPassword/${user.userId}" style="display:inline;">
                            <button type="submit" class="reset-btn" onclick="return confirm('是否为用户生成新密码？')">重置密码</button>
                        </form>
                    </c:if>

                    <!-- 如果用户状态是已注销或不通过，不显示任何按钮 -->
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

</div>

</body>
</html>
